package logic

import (
	"cart_srv/model/redis"
	"context"
	"errors"

	"cart_srv/cart"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListCartLogic {
	return &ListCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListCartLogic) ListCart(in *cart.ListCartRequest) (*cart.ListCartResponse, error) {
	list, err := redis.CartList(in.Userid)
	if err != nil {
		logx.Error("列表展示失败")
		return nil, errors.New("购物车列表展示失败")
	}
	return &cart.ListCartResponse{List: list}, nil
}
